import type { Object3D } from 'three/webgpu';

import type { Editor } from '../Editor';

export type BaseCommandJsonType = {
  id: number;
  type: string;
  name: string;
};

abstract class Command {
  public id: number;
  public editor: Editor;
  public updatable: boolean;
  public inMemory: boolean;
  public type: string;
  public name: string;
  public attributeName: string;
  public object?: Object3D;
  constructor(editor: Editor) {
    this.id = -1;
    this.updatable = false;
    this.inMemory = false;
    this.type = '';
    this.name = '';
    this.attributeName = '';
    this.editor = editor;
  }

  toJSON(): BaseCommandJsonType {
    return {
      type: this.type,
      id: this.id,
      name: this.name,
    };
  }

  fromJSON(json: BaseCommandJsonType) {
    this.inMemory = true;
    this.type = json.type;
    this.id = json.id;
    this.name = json.name;
  }

  execute() {
    console.error(`Command: ${this.type} must implement execute().`);
  }

  undo() {
    console.error(`Command: ${this.type} must implement undo().`);
  }

  update(_command: Command) {
    console.error(`Command: ${this.type} must implement update().`);
  }
}

export { Command };
